import api from "../../api/index.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    balance: 0.00,
    ruleSelIndex: 0,
    showRechargePop: false,
    user: {},
    memberCard:{}
  },
  onLoad: function (options) {
    getApp().initLanguage(this)
    wx.setNavigationBarTitle({
      title: this.data.$t.asset.title,
    })
    this.data.user = wx.getStorageSync('user');
    this.data.memberCard = wx.getStorageSync('memberCard');
    this.rechargeRule()
    this.setData({
      balance: this.data.memberCard.balance
    })
  },
  onShow: function () {
    // this.getUserAmount()
    
  },
  async getUserAmount() {
    // api.memberCardInfo({
    //   method: "GET",
    //   id: this.data.memberCard.id
    // }).then((res) => {
      
    // })
  },
  async rechargeRule() {
    this.setData({
      rechargeSendRules: [{
        id: 1,
        confine: 100,
        send: 10
      }, {
        id: 2,
        confine: 200,
        send: 20
      }]
    })

  },
  changePersionNum(e) {
    if (e.currentTarget.dataset.idx == -1) {
      this.data.showRechargePop = true
    }
    this.setData({
      ruleSelIndex: e.currentTarget.dataset.idx,
      showRechargePop: this.data.showRechargePop,
      amount2: null
    })
  },
  submit1() {
    if (this.data.ruleSelIndex == -1) {
      this.setData({
        showRechargePop: true,
        amount2: null
      })
      return
    }
    const amount = this.data.rechargeSendRules[this.data.ruleSelIndex].confine
    this.wxpay(amount);
  },
  onClose() {
    this.setData({
      showRechargePop: false
    })
  },
  submit2() {
    if (!this.data.amount2) {
      wx.showToast({
        title: this.data.$t.asset.amountPlaceholder,
        icon: 'none'
      })
      return
    }
    this.wxpay(this.data.amount2);
  },
  wxpay(money) {
    this.setData({
      paymentShow: true,
      money
    })
  },
  paymentOk(e) {
    console.log(e.detail); // 这里是组件里data的数据
    this.setData({
      paymentShow: false,
      showRechargePop: false
    })
    this.getUserAmount()
  },
  paymentCancel() {
    this.setData({
      paymentShow: false
    })
  },
})